package cn.xjt.Consumer;

import cn.xjt.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * 内容：
 *
 * @author
 * @date 2021/2/28-18:01
 */
@RestController
public class ConsumerController {

	@Autowired
	public RestTemplate restTemplate;
	
//	private static final String Url="http://localhost:8001";
	private static final String Url="http://springcloud-provider-dept";


	@RequestMapping(value = "/getAll",method = RequestMethod.GET)
	public List<Dept> getAll(){
		return restTemplate.getForObject(Url + "/queryAll",List.class);

//		List forObject = restTemplate.getForObject(Url + "/queryAll", List.class);
//		for (Object a:forObject
//		     ) {
//			System.out.println(a);
//		}
//		return forObject;
	}

	@RequestMapping(value = "/getDept/{id}",method = RequestMethod.GET)
	public Dept getOne(@PathVariable("id") Long id){
		return restTemplate.getForObject(Url+"/queryOne/"+id, Dept.class);
	}
	@RequestMapping(value = "/add",method = RequestMethod.GET)
	public String addDept(Dept dept){
		return restTemplate.postForObject(Url+"/add", dept, String.class);
	}
}
